<template>
  <div class="screen-full">
    <div v-show="!isFullscreen" @click="handleFullScreen">全屏模式</div>
    <div v-show="isFullscreen" @click="handleFullScreen">退出全屏</div>
  </div>
</template>

<script>
import screenfull from "screenfull";
export default {
  name: "ScreenFull",
  data() {
    return {
      isFullscreen: false,
    };
  },
  components: {},
  mounted() {
    this.init();
  },
  beforeDestroy() {
    this.destroy();
  },
  methods: {
    handleFullScreen() {
      if (!screenfull.isEnabled) {
        this.$message.info("您的浏览器版本过低，不支持全屏浏览");
        return false;
      }
      screenfull.toggle();
    },
    change() {
      this.isFullscreen = screenfull.isFullscreen;
    },
    init() {
      if (screenfull.isEnabled) {
        screenfull.on("change", this.change);
      }
    },
    destroy() {
      if (screenfull.isEnabled) {
        screenfull.off("change", this.change);
      }
    },
  },
};
</script>

<style scoped lang="less">
.screen-full {
 

  div {
    position: absolute;
    width: 80px;
    height: 35px;
    right: 500px;
    top: 20px;
    line-height: 35px;
    color: #fff;
    border-radius: 5px;
    text-align: center;
    background-color: #224751;
  }
}
@media screen and (max-width: 1300px) {
  .screen-full {
    div {
      right: 400px;
      top: 20px;
    }
  }
}
</style>
